package mianyang.zhangsan.com.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonAlias;
import mianyang.zhangsan.com.pojo.Teacher;
import mianyang.zhangsan.com.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    /**
     * combobox列表查询
     * @return
     */
    @RequestMapping("/comboboxList")
    @ResponseBody
    public Object comboboxList(){
        List<Teacher> teachers = teacherService.queryInfoAll();
        return teachers;
    }

    /**
     * 教师列表请求
     * @param page
     * @param rows
     * @param clazzId
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object list(
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "rows", defaultValue = "10") int rows,
            @RequestParam(value = "clazzId", defaultValue = "0") int clazzId){
        Page<Teacher> teacherPage = teacherService.queryByPage(page, rows, clazzId);
        Map<String, Object> map = new HashMap<>();
        map.put("total", teacherPage.getPages());
        map.put("rows", teacherPage.getRecords());
        return map;
    }
}
